package com.five.matebook.utils;

import android.content.Context;
import android.content.SharedPreferences;

import org.json.JSONException;
import org.json.JSONObject;

public class SharedPreferencesUtil {
    private static final String PREF_NAME = "MyPrefs";
    private static final String KEY_JSON_DATA = "json_data";

    public static void saveJsonData(Context context, String json) {
        saveJsonData(context, KEY_JSON_DATA, json);
    }

    public static void saveJsonData(Context context, String key, String json) {
        SharedPreferences sharedPreferences = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(key, json);
        editor.apply();
    }

    public static String getJsonData(Context context) {
        return getJsonData(context, KEY_JSON_DATA);
    }

    public static String getJsonData(Context context, String key) {
        SharedPreferences sharedPreferences = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
        return sharedPreferences.getString(key, null);
    }
}
